package TestServlet.TestSession;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class TestSession1 implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("响应用户请求");
        //开启回话管理
        HttpServletRequest servletRequest1=(HttpServletRequest) servletRequest;
        HttpSession session = servletRequest1.getSession();
        System.out.println(session.getId());
        session.setAttribute("java","后端加前端");
        Object java = session.getAttribute("java");
        System.out.println("java="+java);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
